home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #48 (Sep 89) / Zoundz Source / Zoundz.Pas < prev    next >
Pascal/Delphi Source File  |  1989-05-01  |  10KB  |  325 lines

  1. program Zoundz;
  2. {Program name:  Zoundz.Pas  }
  3. {Function:  Allows creation of 'snd ' resource ID=9000.  }
  4. {History: 4/17/89 Original by Prototyper.   }
  5. {Modified: 5/1/89 by Kirk Chase}
  6.     uses
  7.         PrintTraps, Message, save_changes, About, Untitled, InitTheMenus, HandleTheMenus, Sound, MyGlobals, MyFileStuff, MyPrintStuff;
  8.  
  9.     const
  10.         WNETrapNum = $60;
  11.         UnImplTrapNum = $9F;
  12.         MultiEvt = 15;
  13.         bit0 = 31;
  14.         GrayRgnLowMemGlobal = $9EE;
  15.  
  16.     var                                 {Main variables}
  17.         myEvent: EventRecord;
  18.         ResumePeek: WindowPeek;
  19.         theWorld: SysEnvRec;
  20.         doneFlag, DoIt, WNE, sysResult: boolean;
  21.         code, theValue: integer;
  22.         whichWindow: WindowPtr;
  23.         dragRect: Rect;
  24.         mResult: longint;
  25.         theMenu, theItem: integer;
  26.         chCode: integer;
  27.         ch: char;
  28.         myPt: Point;
  29.         title: str255;
  30.         nDocs, message, index, sleep: integer;
  31.         theFile: AppFile;
  32.         theErr: OSErr;
  33.  
  34.     procedure InitMac; {initializes Macintosh}
  35.     begin
  36.         MoreMasters;                    {This reserves space for more handles}
  37.         InitGraf(@thePort);             {Quickdraw Init}
  38.         InitFonts;                      {Font manager init}
  39.         InitWindows;                    {Window manager init}
  40.         InitMenus;                      {Menu manager init}
  41.         TEInit;                         {Text edit init}
  42.         InitDialogs(nil);               {Dialog manager}
  43.  
  44.         FlushEvents(everyEvent, 0);{Clear out all events}
  45.         InitCursor;                     {Make an arrow cursor}
  46.     end;
  47.  
  48.     procedure InitApp; {initialize application}
  49.         var
  50.             tempHandle: handle;
  51.     begin
  52.         doneFlag := FALSE;              {Do not exit program yet}
  53.         Init_My_Menus;                  {Initialize menu bar}
  54.         MyDoc := DocPtr(NewPtr(sizeof(DocRec))); {get doc}
  55.         ThePrintRec := nil; {print initialization}
  56.         PrOpen;
  57.         tempHandle := NewHandle(sizeof(TPrint));
  58.         ThePrintRec := THPrint(tempHandle);
  59.         PrintDefault(ThePrintRec);
  60.         PageRect := ThePrintRec^^.prInfo.rpage;
  61.         PrClose;
  62.  
  63.         dragRect := screenbits.bounds;{Get screen area,  l,t,r,b, drag area}
  64.         SetRect(dragRect, dragRect.Left + 10, dragRect.Top + 25, dragRect.Right - 10, dragRect.Bottom - 10);
  65.         SetRect(NotePallete, 5, 5, 235, 260);{set various rectangles}
  66.         SetRect(EndRect, 345, 235, 370, 250);
  67.         SetRect(StartRect, 345, 195, 370, 210);
  68.         SetRect(TimbreRect, 465, 85, 490, 100);
  69.         SetRect(DurRect, 465, 65, 490, 80);
  70.         SetRect(AmpRect, 465, 45, 490, 60);
  71.         SetRect(FreqRect, 465, 25, 500, 40);
  72.         SetRect(NoteRect, 420, 5, 445, 20);
  73.  
  74.         Dirty := false;
  75.  
  76.         theWatch := GetCursor(watchCursor);
  77.         HLock(Handle(theWatch));
  78.         theSquare := GetCursor(crossCursor);
  79.         HLock(Handle(theSquare));
  80.  
  81.         theErr := SysEnvirons(1, theWorld);
  82.         if (theWorld.machineType >= 0) and (NGetTrapAddress(WNETrapNum, ToolTrap) = NGetTrapAddress(UnImplTrapNum, ToolTrap)) then
  83.             WNE := false
  84.         else
  85.             WNE := true;
  86.         sleep := 10;
  87.     end;
  88.  
  89.     procedure AdjustCursor; {set cursor}
  90.     begin
  91.         if (FrontWindow = MyWindow) and (MyWindow <> nil) then
  92.             begin {our window in front}
  93.                 GetMouse(myPt);
  94.                 if PtInRect(myPt, NotePallete) then
  95.                     SetCursor(theSquare^^) {over note pallete}
  96.                 else
  97.                     SetCursor(arrow); {over other stuff}
  98.             end
  99.         else
  100.             SetCursor(arrow);
  101.     end;
  102.  
  103. begin                               {Start of main body}
  104.     InitMac;
  105.     InitApp;
  106.  
  107.     {finder startup}
  108.     CountAppFiles(message, nDocs);
  109.     if nDocs = 0 then
  110.         begin {no files to open}
  111.             Init_Untitled;                  {Initialize the window routines}
  112.             Open_Untitled;        {Open the window routines at program start}
  113.         end
  114.     else
  115.         begin {files to print or open}
  116.             if message = appPrint then
  117.                 begin {print docs}
  118.                     for index := 1 to nDocs do
  119.                         begin {Loop through docs}
  120.                             GetAppFiles(index, theFile);
  121.                             if theFile.fType = 'ZZDC' then
  122.                                 begin {my file}
  123.                                     VolRefNum := theFile.vRefNum;
  124.                                     FileName := theFile.fName;
  125.                                     OpenFile;
  126.                                     if VolRefNum <> 0 then
  127.                                         begin
  128.                                             Open_Untitled;
  129.                                             SetWTitle(MyWindow, FileName);
  130.                                             doPrint;
  131.                                             Close_Untitled(MyWindow);
  132.                                         end;
  133.                                 end;
  134.                             ClrAppFiles(index);
  135.                         end; {Loop through docs}
  136.                     doneFlag := true; {quit when done}
  137.                 end {print docs}
  138.             else
  139.                 begin {open first file, can't open multiple}
  140.                     GetAppFiles(1, theFile);
  141.                     if theFile.fType = 'ZZDC' then
  142.                         begin
  143.                             VolRefNum := theFile.vRefNum;
  144.                             FileName := theFile.fName;
  145.                             OpenFile;
  146.                             if VolRefNum = 0 then
  147.                                 begin
  148.                                     Init_Untitled;                  {Initialize the window routines}
  149.                                     FileName := 'Untitled';
  150.                                 end;
  151.                             Open_Untitled;        {Open the window routines at program start}
  152.                             SetWTitle(MyWindow, FileName);
  153.                             for index := 1 to nDocs do
  154.                                 ClrAppFiles(index);
  155.                         end;
  156.                 end;
  157.         end;
  158.  
  159.     repeat                          {Start of main event loop}
  160.         AdjustMenus;
  161.         AdjustCursor;
  162.  
  163.         if WNE then
  164.             DoIt := WaitNextEvent(everyEvent, myEvent, sleep, nil)
  165.         else
  166.             begin
  167.                 SystemTask;
  168.                 DoIt := GetNextEvent(everyEvent, myEvent);
  169.             end;
  170.  
  171.         if DoIt then{If event then...}
  172.             begin                   {Start handling the event}
  173.                 code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
  174.  
  175.                 case myEvent.what of{Decide type of event}
  176.                     MouseDown:{Mouse button pressed}
  177.                         begin
  178.                             if (code = inMenuBar) then{See if a menu selection}
  179.                                 begin
  180.                                     mResult := MenuSelect(myEvent.Where);
  181.                                     theMenu := HiWord(mResult);{Get the menu list number}
  182.                                     theItem := LoWord(mResult);{Get the menu list item number}
  183.                                     Handle_My_Menu(doneFlag, theMenu, theItem);
  184.                                 end;{End of inMenuBar}
  185.  
  186.                             if (code = InDrag) then{See if in a window drag area}
  187.                                 begin
  188.                                     DragWindow(whichWindow, myEvent.where, dragRect);{Drag the window}
  189.                                 end;{End of InDrag}
  190.  
  191.                             if (code = inGoAway) then{See if in a window goaway area}
  192.                                 begin
  193.                                     if TrackGoAway(whichWindow, myEvent.where) then
  194.                                         begin
  195.                                             if dirty then
  196.                                                 begin {need saving}
  197.                                                     GetWTitle(MyWindow, title);
  198.                                                     ParamText(title, '', '', '');
  199.                                                     theValue := D_save_changes;
  200.                                                     if (theValue = I_Yes) then
  201.                                                         begin {wants to save changes}
  202.                                                             if VolRefNum = 0 then
  203.                                                                 doSaveAs
  204.                                                             else
  205.                                                                 doSave;
  206.                                                             if VolRefNum <> 0 then {did not cancel saving}
  207.                                                                 Close_Untitled(MyWindow);
  208.                                                         end
  209.                                                     else if theValue = I_No then
  210.                                                         Close_Untitled(MyWindow);
  211.                                                 end {of needing saved}
  212.                                             else {no need to save}
  213.                                                 Close_Untitled(MyWindow);
  214.                                         end;
  215.                                 end;{End of InGoAway}
  216.  
  217.                             if (code = inContent) then{See if in a window}
  218.                                 begin
  219.                                     if (whichWindow <> FrontWindow) then
  220.                                         SelectWindow(whichWindow)
  221.                                     else
  222.                                         begin
  223.                                             SetPort(whichWindow);
  224.                                             Do_Untitled(myEvent);
  225.                                         end;
  226.                                 end;{End of inContent}
  227.  
  228.                             if (code = inSysWindow) then{See if a DA selection}
  229.                                 SystemClick(myEvent, whichWindow);
  230.                         end;        {End of MouseDown}
  231.  
  232.                     KeyDown, AutoKey:{Handle key inputs}
  233.                         begin
  234.                             with myevent do
  235.                                 begin
  236.                                     chCode := BitAnd(message, CharCodeMask);{Get character}
  237.                                     ch := CHR(chCode);
  238.                                     if (Odd(modifiers div CmdKey)) then{See if Command key is down}
  239.                                         begin
  240.                                             mResult := MenuKey(ch);{See if menu selection}
  241.                                             theMenu := HiWord(mResult);{Get the menu list number}
  242.                                             theItem := LoWord(mResult);{Get the menu item number}
  243.                                             if (theMenu <> 0) then
  244.                                                 Handle_My_Menu(doneFlag, theMenu, theItem);
  245.                                         end;
  246.                                 end;
  247.                         end;        {End for KeyDown,AutoKey}
  248.  
  249.                     UpDateEvt:{Update event for a window}
  250.                         begin
  251.                             whichWindow := WindowPtr(myEvent.message);
  252.                             BeginUpdate(whichWindow);
  253.                             Update_Untitled(whichWindow);{Update this window}
  254.                             EndUpdate(whichWindow);
  255.                         end;        {End of UpDateEvt}
  256.  
  257.                     DiskEvt:       {Disk inserted event}
  258.                         begin
  259.                             if (HiWord(myevent.message) <> noErr) then{See if a diskette mount error}
  260.                                 begin{due to unformatted diskette inserted}
  261.                                     myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);
  262.                                     myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);
  263.                                     InitCursor;
  264.                                     chCode := DIBadMount(myEvent.where, myevent.message);{Let the OS handle the diskette}
  265.                                 end;
  266.                         end;       {End of DiskEvt}
  267.  
  268.                     ActivateEvt:{Window activated event}
  269.                         begin
  270.                             whichWindow := WindowPtr(myevent.message);
  271.                             if odd(myEvent.modifiers) then{Activate, not DeActivate}
  272.                                 begin{Handle the activate}
  273.                                     SelectWindow(whichWindow);
  274.                                 end;
  275.                         end;        {End of ActivateEvt}
  276.  
  277.                     MultiEvt: 
  278.                         begin
  279.                             if Odd(myEvent.message) then
  280.                                 begin {resume event}
  281.                                     if FrontWindow = MyWindow then
  282.                                         begin
  283.                                             SetPort(MyWindow);
  284.                                             InvalRect(MyWindow^.portRect);
  285.                                         end
  286.                                     else if FrontWindow <> nil then
  287.                                         begin
  288.                                             ResumePeek := WindowPeek(FrontWindow);
  289.                                             if ResumePeek^.windowKind < 0 then
  290.                                                 begin
  291.                                                     myEvent.what := activateEvt;
  292.                                                     BitSet(@myEvent.modifiers, bit0);
  293.                                                     sysResult := SystemEvent(myEvent);
  294.                                                 end;
  295.                                         end;
  296.                                 end {of resume event}
  297.  
  298.                             else {suspend event}
  299.                                 begin
  300.                                     if FrontWindow = MyWindow then
  301.                                         begin
  302.                                             SetPort(MyWindow);
  303.                                             InvalRect(MyWindow^.portRect);
  304.                                         end
  305.                                     else if FrontWindow <> nil then
  306.                                         begin
  307.                                             ResumePeek := WindowPeek(FrontWindow);
  308.                                             if ResumePeek^.windowKind < 0 then
  309.                                                 begin
  310.                                                     myEvent.what := activateEvt;
  311.                                                     BitClr(@myEvent.modifiers, bit0);
  312.                                                     sysResult := SystemEvent(myEvent);
  313.                                                 end;
  314.                                         end;
  315.                                 end;
  316.                         end; {of MultiEvt}
  317.  
  318.                     otherwise
  319.                         ;
  320.                 end;                {End of case}
  321.  
  322.             end;                    {end of GetNextEvent}
  323.     until doneFlag;                 {End of the event loop}
  324.  
  325. end.                                    {End of the program}